package com.aysafety.iotdataplatformweb.configurer;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.aysafety.core.DBDriver.hbase.HBaseDriver;

@Component
@Order(2)
public class ApiServer implements CommandLineRunner {
    private Logger logger = LoggerFactory.getLogger(ApiServer.class);

    @Autowired
    HBaseConfigurer hBaseConfigurer;

    public void run(String... args) {
        try {
            HBaseDriver.setZKConfig(hBaseConfigurer.getZkHost(), hBaseConfigurer.getZkPort());
            HBaseDriver.connection();
            logger.info("ApiServer启动中...");
        } catch (Exception e) {
            logger.error("ApiServer异常了:", e);
            try {
                HBaseDriver.close();
            } catch (IOException e1) {
                logger.error("ApiServer异常了:", e1);
            }
        }
    }
}
